package com.example.fw;

import java.util.List;
import java.util.Random;

import org.openqa.selenium.WebElement;

public class RandomGenerator extends WebDriverHelperBase{
	
	public RandomGenerator(AppManager manager) {
		super(manager);
	}
	
	public static String generateString(){
		Random rnd = new Random();
		Random rnd1 = new Random();
		String temp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String str = "";
		int random = rnd.nextInt(10);
		for (int i=0;i<random;i++){
			int pos = rnd1.nextInt(52);
			str=str+temp.subSequence(pos, pos+1);
		}
		
		if (random == 0)
			return "";
		else
			return str; 
	}
	
	public static String generateNumber(){
		Random rnd = new Random();
		Random rnd1 = new Random();
		String temp = "0123456789";
		String str = "";
		int random = rnd.nextInt(10);
		for (int i=0;i<random;i++){
			int pos = rnd1.nextInt(10);
			str=str+temp.subSequence(pos, pos+1);
		}
		
		if (random == 0)
			return "";
		else
			return str; 
	}
	
	public static String generateLimitedNumber(int max){
		Random rnd = new Random();
		return (rnd.nextInt(max)+1)+"";
	}
	
	public static String generateStringFixLength(int length){
		Random rnd = new Random();
		String temp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String str = "";
		for (int i = 0; i < length; i++){
			int pos = rnd.nextInt(52);
			str=str+temp.subSequence(pos, pos+1);
		}
		return str;
	}
	
	public static String generateNumberFixLength(int length){
		Random rnd = new Random();
		String temp = "0123456789";
		String str = "";
		for (int i = 0; i < length; i++){
			int pos = rnd.nextInt(10);
			str=str+temp.subSequence(pos, pos+1);
		}
		return str;
	}
	
	public static String generateEmail(){
		String host[] = {"mail.ru","list.ru","bk.ru","yandex.ru","rambler.ru","pochta.ru","mail.com"};
		Random rnd = new Random();
		if (generateString() == "")
			return "";
		else
			return "test"+generateString() + "@" + host[rnd.nextInt(host.length)];
	}
	
	public static String generateYear(){
		if (generateString() == "")
			return "";
		else
			return "19"+generateNumberFixLength(2);
	}
	
	public static String generateMobilePhone(){
		if (generateString() == "")
			return "";
		else
			return "8-("+generateNumberFixLength(3)+")-"+generateNumberFixLength(3)+"-"+generateNumberFixLength(2)+"-"+generateNumberFixLength(2);
	}
	
	public static String generateHomePhone(){
		if (generateString() == "")
			return "";
		else
			return generateNumberFixLength(3)+"-"+generateNumberFixLength(2)+"-"+generateNumberFixLength(2);
	}
	
	public static String generateAddress(){
		if (generateString() == "")
			return "";
		else
			return generateStringFixLength(10)+" street "+generateNumberFixLength(2)+"/"+generateNumberFixLength(2);
	}
	
	public static String generateValueFromList(List<WebElement> list){
		Random rnd = new Random();
		String array[] = new String[list.size()];  
		for (int i = 0; i < list.size(); i++)
			array[i]=list.get(i).getText();
		int random = rnd.nextInt(list.size()-1);
		return array[random];
	}
}
